Fix floating point precision issue with "--bumpslopes" exporter #1913
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch stores the slope values in (i,j) texture space rather than in normalized s,t space to prevent floating point precision issue when dealing with very high resolution textures.
This was particularly sensitive with half precision format where the square slopes can cause floating point overflow (because the width of 1 texel is 1.0 / res_x in (s,t) space).
To retrieve the slopes in normalized (s,t) space, we just need to scale the slopes with the texture resolution as follow:
dhds = dhds *res_x
dhdt = dhdt * res_y
dhds2 = dhds2 * res_x * res_x
dhdt2 = dhdt2 * res_y * res_y
dh2dsdt = dh2dsdt * res_x * res_y